#! /usr/bin/python
# encoding=utf-8
# Created by Fenglu Niu on 2025/5/9 14:56
import base64
import random
import string

from captcha.image import ImageCaptcha
from fastapi import APIRouter

from api import R

router = APIRouter(prefix='/sys', tags=["sys"])


@router.get('/captcha')
async def captcha():
    image = ImageCaptcha()
    text = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(4))
    captcha = image.generate(text)
    captcha_base64 = base64.b64encode(captcha.getvalue()).decode('utf-8')
    result = {'text': text, 'captcha': captcha_base64}
    return R.ok(data=result)


@router.get('/asr_config')
async def asr_config():
    return R.ok(data={"tId": 'AKIDA7pKsBL1lFTR8aAjUzFFyVR9f5F9MERO',
                      'tKey': 'tYw4xZvEh6MLUSG4kgT9geT1KODmDrPj',
                      'appid': '1252106759'
                      })
